<?php

class User extends Model
{
	public function tableName()
	{
		return 'user';
	}

	public function rules()
	{
		return array(
			array('username, password, status, fullname, lastvisited', 'required'),
			array('status', 'numerical', 'integerOnly'=>true),
			array('username, password, fullname, lastvisited', 'length', 'max'=>255),
			array('user_id, username, password, status, fullname, lastvisited', 'safe', 'on'=>'search'),
		);
	}

	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	public function attributeLabels()
	{
		return array(
			'user_id' => 'User',
			'username' => 'Username',
			'password' => 'Password',
			'status' => 'Status',
			'fullname' => 'Fullname',
			'lastvisited' => 'Lastvisited',
		);
	}

	public function search()
	{
		$criteria=new CDbCriteria;

		$criteria->compare('user_id',$this->user_id);
		$criteria->compare('username',$this->username,true);
		$criteria->compare('password',$this->password,true);
		$criteria->compare('status',$this->status);
		$criteria->compare('fullname',$this->fullname,true);
		$criteria->compare('lastvisited',$this->lastvisited,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}

    public function hashPassword($password) {
        return md5($password);
    }

    public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
}
